<?php

namespace App\Master\Home;

use App\Master\Framework\Extend\Module;
use App\Models\Arts\WebMenusBottomModel;
use App\Models\Arts\WebMenusModel;
use App\Models\Arts\WebPartnerModel;
use Illuminate\Support\Facades\Cache;

class CacheSystem
{

    const WEB_MENUS = 'WEB_MENUS:';
    const WEB_MENUS_BOTTOM = 'WEB_MENUS_BOTTOM:';
    const WEB_SITE = 'WEB_SITE:';
    const WEB_PARTNER = 'WEB_PARTNER:';

    /**
     * 导航缓存
     * @param string $path
     * @return mixed
     */
    public static function createMenus(string $path = '')
    {
//        $path = explode('/',$path);
//        $path = $path[0] ?? '';
        return Cache::remember(self::WEB_MENUS, 0, function () use ($path) {
            return WebMenusModel::getMenusParentsRecursion($path);
        });
    }

    /**
     * 站点信息缓存
     * @return mixed
     */
    public static function createSite()
    {
        return Cache::remember(self::WEB_SITE, 0, function () {
            return Module::_SetupModule('siteBase');
        });
    }

    public static function createPartner()
    {
        return Cache::remember(self::WEB_PARTNER, 0, function () {
            return WebPartnerModel::query()
                ->where('status',1)
                ->where('is_delete',0)
                ->orderBy('sort','desc')
                ->get()
                ->toArray();
        });

    }
}